package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.Vo.OrderVo;
import com.jingjiu.homeservicesapi.domain.Order;
import com.jingjiu.homeservicesapi.util.R;
import com.jingjiu.homeservicesbiz.service.OrderServiceImpl;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 通用订单主：记录收货信息、联系人等Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/order")
public class OrderController
{

    @Autowired
    private OrderServiceImpl orderService;



    /**
     * 查询通用订单主：记录收货信息、联系人等列表
     */

    @GetMapping("/page")
    @ResponseBody
    public R<Page<OrderVo>> list(@ParameterObject Page page, @ParameterObject OrderVo orderVo)
    {
        Page<OrderVo> page1 = orderService.selectOrderList(page, orderVo);
        if(page1==null) return R.failed();
        return R.ok(page1);
    }

    /**
     * 导出通用订单主：记录收货信息、联系人等列表
     */


    /**
     * 新增保存通用订单主：记录收货信息、联系人等
     */

    @PostMapping("/add")
    @ResponseBody
    public R addSave(Order order)
    {
        int flag=orderService.insertOrder(order);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }

    /**
     * 修改通用订单主：记录收货信息、联系人等
     */

    @GetMapping("/get/{id}")
    public R<Order> getById(@PathVariable("id") Long id)
    {
        Order order = orderService.selectOrderById(id);
        if(order==null) return R.failed();
        return R.ok(order);
    }

    /**
     * 修改保存通用订单主：记录收货信息、联系人等
     */

    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody Order order)
    {
        int flag=orderService.updateOrder(order);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }

    /**
     * 删除通用订单主：记录收货信息、联系人等
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R remove(Long id)
    {
        int flag=orderService.deleteOrderById(id);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }
}
